
//
//  GDDetailsViewController.m
//  美团试验 (自己)
//
//  Created by 热带雨林 on 17/2/14.
//  Copyright © 2017年 热带雨林. All rights reserved.
//

#import "GDDetailsViewController.h"
#import "Masonry.h"
#import "UIImageView+WebCache.h"
#import "GDDetailsHeadView.h"

@interface GDDetailsViewController ()<UITableViewDelegate>

@property(nonatomic, weak)UILabel  *label;
@property(nonatomic, weak)UIImageView *imageV;
@property(nonatomic, weak)UITableView *tabel;

@end

@implementation GDDetailsViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    if(self.navigationController.viewControllers.count > 1){
        self.tabBarController.tabBar.hidden = YES;
    }else{
        self.tabBarController.tabBar.hidden = NO;
    }
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    
    self.tabBarController.hidesBottomBarWhenPushed = NO;
    self.tabBarController.tabBar.hidden = NO;
    
}
- (void)viewDidLoad {

    [super viewDidLoad];
    
    [self setupUI];
    
}
- (void)setupUI{
    self.view.backgroundColor = [UIColor whiteColor];
    //创建一个图片
    UIImageView *pictureImage = [[UIImageView alloc]init];
    pictureImage.backgroundColor = [UIColor blueColor];
    self.imageV = pictureImage;
    [self.view addSubview:pictureImage];
    [pictureImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(self.view);
        make.left.top.equalTo(self.view);
        make.height.mas_equalTo(400);
    }];
    //特别是，弹出来的控制器 ，此时是所有的控件还是没有创建出来，如果是视图，就可以这么使用
    //注意，在控制器中setModel的方法在viewDidload之前，控件还没有加载出来，所以不能赋值
    NSString *str = [_detailsModel.picture stringByDeletingPathExtension];
    NSURL *url = [NSURL URLWithString:str];
    [pictureImage sd_setImageWithURL:url];
    //将图片填满
    pictureImage.contentMode = UIViewContentModeScaleAspectFill;
    //创建一个tableView将整个视图盖住
    UITableView *table = [[UITableView alloc]init];
    table.contentInset = UIEdgeInsetsMake(400, 0, 0, 0);
    table.backgroundColor = [UIColor clearColor];
    //监听视图的滚动
    table.delegate = self;
    //设置一个空的footView 相当于一个展位图，显示空的tableView
    table.tableFooterView  = [[UIView alloc]init];
    self.tabel = table;
    table.showsHorizontalScrollIndicator = NO;
    table.showsVerticalScrollIndicator = NO;
    [self.view addSubview:table];
    [table mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.equalTo(self.view);
    }];
    //添加表头视图
    GDDetailsHeadView *headView = [[GDDetailsHeadView alloc]init];
    headView.detailsModel = _detailsModel;
    headView.frame = CGRectMake(0, 0, 0, 400);
    table.tableFooterView = headView;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    CGPoint offset = scrollView.contentOffset;
    
    CGFloat height = -offset.y;

    [_imageV mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(height);
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
